<?php

namespace app\index\controller;

class Article extends Home
{
    protected $beforeActionList = [
        'check_load' => ['except' => 'one']
    ];

    /**
     * 初始化
     */
    public function _initialize()
    {
        parent::_initialize();
    }


    /**
     * 信息列表
     */
    public function index()
    {
//        $id = Db('document')->where('status', 1)->select();
//        $map['category_id'] = array('in', $id);
//        $map['status'] = 1;
        $list = Db('document')->where('status', 1)->paginate(20);
        $page = $list->render();
        $this->assign('_list', $list);
        $this->assign('page', $page);
        $this->assign('title', lang('document'));
        return $this->fetch();
    }

    /**
     * 信息详情
     */
    public function one()
    {
        $id = input('id');
        $map['id'] = $id;
        $map['status'] = 1;
        Db('Document')->where($map)->setInc('view');
        $ainfo = Db('Document')->where($map)->find();
        if (!$ainfo) {
            $this->apiError('改文章不存在！');
        }

        $ainfo['update_time'] = date('Y-m-d H:i:s', $ainfo['update_time']);

        $this->apiSuccess('文章详情', $ainfo);
    }
}

